package common.exceptions;

/**
 * Created with IntelliJ IDEA.
 * User: Matan
 * Date: 12/4/13
 * Time: 10:28 PM
 */
public class SemanticError extends Exception {

    private int line;
    private String value;

    public SemanticError(String message, int line, String value) {
        super(message);
        this.line = line;
        this.value = value;
    }

    public SemanticError(int line, String message) {
        super(message);
        this.line = line;
    }

    public SemanticError(String message, String value) {
        super(message);
        this.line = -1;
        this.value = value;
    }

    public SemanticError(String message) {
        super(message);
        this.line = -1;
    }

    /**
     * returns a string representation for the error with line number, message and the token that
     * caused the syntax error
     */
    public String toString() {
        if(value != null)
            return line + ": semantic error; " + getMessage() + ": " + value;
        else
            return line + ": semantic error; " + getMessage();
    }

    /**
     * set the error's line
     * @param line line
     */
    public void setLine(int line) {
        this.line = line;
    }

    /**
     * @return line
     */
    public int getLine() {
        return line;
    }
}
